home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / t_os / tacop / eupbug.c < prev    next >
Text File  |  1993-11-30  |  3KB  |  128 lines

  1. /*
  2.     EUPドライバを終了処理を全て削除し動作させる
  3.     compile usage : run386 hcd386p eupbug
  4.     link usage    : run386 tlinkp eupbug -lib hce snd tbios -tc -s 77824
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <snd.h>
  10. #include <mos.h>
  11.  
  12. int eup_load();
  13.  
  14. char swork[16384];
  15. char mwork[MosWorkSize];
  16. char *eup_buf;
  17. int flen,signature;
  18. FILE *fp;
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22.     int ret,tr,x,y;
  23.  
  24.     if (argc < 2){
  25.         printf("usage:RUN386 EUPBUG <EUP filename>\n");
  26.         return(1);
  27.         }
  28.  
  29.     SND_init(swork);
  30.     MOS_start(mwork,MosWorkSize);
  31.     SND_elevol_set(0,127,127);
  32.     SND_elevol_mute(0x0f);
  33.  
  34.     SND_eup_init();
  35. //    SND_rs_midi_init();
  36.  
  37.     if((fp = fopen(argv[1],"rb")) == NULL){
  38.         ret = 1;
  39.         goto err_end;
  40.         }
  41.     ret = eup_load();
  42.     fclose(fp);
  43.  
  44.     if (!ret){
  45.         SND_eup_play_start(eup_buf,flen,signature);
  46.         do {
  47.             MOS_rdpos(&tr,&x,&y);
  48.             } while(SND_eup_stat_flag() && (tr != 0x03));
  49. //        SND_eup_play_stop();
  50. //        free(eup_buf);
  51.         }
  52. err_end:
  53. //    SND_rs_midi_end();
  54. //    SND_eup_end();
  55. //    MOS_end();
  56. //    SND_end();
  57.     return(ret);
  58. }
  59.  
  60. int eup_load()
  61. {
  62.     int i,j,size,tempo;
  63.     char buffer[160];
  64.     char bankpath[128];
  65.     char fm_bankname[16];
  66.     char pcm_bankname[16];
  67.  
  68.     fseek(fp,0,SEEK_END);
  69.     flen = (unsigned int)ftell(fp);
  70.     fseek(fp,0,SEEK_SET);
  71.     if (flen <= 2048+4+1+1)
  72.         return(1);
  73.  
  74.     fseek(fp,852,SEEK_SET);
  75.     fread(buffer,1,160,fp);
  76.     for(i=0 ; i<32 ;i++){
  77.         SND_eup_mute_set(i,(int)buffer[i]);
  78.         SND_eup_port_set(i,(int)buffer[32+i]);
  79.         SND_eup_midi_ch_set(i,(int)buffer[64+i]);
  80.         SND_eup_bias_set(i,(int)buffer[96+i]);
  81.         SND_eup_transpose_set(i,(int)buffer[128+i]);
  82.         }
  83.     fseek(fp,1748,SEEK_SET);
  84.     fread(buffer,1,6,fp);
  85.     for(i = 0;i < 6;i++)
  86.         SND_midi_ch_assign(i,(int)buffer[i]);
  87.     fread(buffer,1,8,fp);
  88.     for(i = 0;i < 8;i++)
  89.         SND_midi_ch_assign(i+64,(int)buffer[i]);
  90.  
  91.     memset(bankpath,0,128);
  92.     fread(&bankpath[0],1,8,fp);
  93.     if(bankpath[0] != '\0'){
  94.         for(j= 0;bankpath[j] != '\0';j++);
  95.         bankpath[j+0] = '.';
  96.         bankpath[j+1] = 'f';
  97.         bankpath[j+2] = 'm';
  98.         bankpath[j+3] = 'b';
  99.         bankpath[j+4] = '\0';
  100.         SND_fm_bank_load(bankpath,fm_bankname);
  101.         }
  102.  
  103.     memset(bankpath,0,128);
  104.     fread(&bankpath[0],1,8,fp);
  105.     if(bankpath[0] != '\0'){
  106.         for(j= 0;bankpath[j] != '\0';j++);
  107.         bankpath[j+0] = '.';
  108.         bankpath[j+1] = 'p';
  109.         bankpath[j+2] = 'm';
  110.         bankpath[j+3] = 'b';
  111.         bankpath[j+4] = '\0';
  112.         SND_pcm_bank_load(bankpath,pcm_bankname);
  113.         }
  114.  
  115.     fseek(fp,2048,SEEK_SET);
  116.     fread(&size,4,1,fp);
  117.     fread(buffer,1,2,fp);
  118.     signature = (int)buffer[0];
  119.     tempo = (int)buffer[1];
  120.     SND_eup_tempo_set(tempo);
  121.  
  122.     flen -= 2048+4+1+1;
  123.     if ((eup_buf = malloc(flen)) == 0)
  124.         return(1);
  125.     fread(eup_buf,1,flen,fp);
  126.     return(0);
  127. }
  128.